package com.mercury.security.config;

import com.mercury.security.constants.CacheConstants;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;

/**
 * TokenStore 配置
 *
 * @author mercury
 */
public class AuthTokenStoreAutoConfiguration {

    @Bean
    public TokenStore tokenStore(RedisConnectionFactory redisConnectionFactory) {
        //这边使用RedisTokenStore将令牌存储到Redis中
        RedisTokenStore tokenStore = new RedisTokenStore(redisConnectionFactory);
        tokenStore.setPrefix(CacheConstants.PROJECT_OAUTH_ACCESS);
        return tokenStore;
    }

}
